import React, { useEffect, useState } from 'react';
import {
  Button,
  Form,
  Input,
  InputNumber,
  Radio,
} from 'antd';
import * as asyncfn from '../../store/crmslice'
import { useDispatch, useSelector } from 'react-redux';
const Myfrom = (props) => {
    let obj=useSelector(state=>state.todos)
    let dispatch=useDispatch()
    const [form] = Form.useForm();
    useEffect(()=>{
        form.setFieldsValue(props.itemobj)
    },[])
    const onFinish = values => {
    if(props.titlee=="添加"){
        let obj={
            ...values,
            id:new Date().getTime(),
        }
        dispatch(asyncfn.async_addshoplist(obj))
    }else{
        let obj={
            ...values,
            id:props.itemobj.id
        }
        dispatch(asyncfn.async_editshoplist(obj))
    }
    props.onCancel()   
  };
  return (
    <Form form={form} onFinish={onFinish}> 
      <Form.Item label="优惠券名称" name="title"  rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="优惠券面值" name="mianzhi"  rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="优惠券最低消费" name="xiaofei" rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="优惠券有效期限" name="qixian" rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="排序" name="paixu" rules={[{ required: true, message: 'Please input your username!' }]}>
        <InputNumber />
      </Form.Item>
      <Form.Item label="状态" name="zhuangtai" rules={[{ required: true, message: 'Please input your username!' }]}>
        <Radio.Group
            options={[
            { value: true, label: '开启' },
            { value: false, label: '关闭' },
            ]}
        />
      </Form.Item>
      <Form.Item>
        <Button htmlType="submit">Button</Button>
      </Form.Item>
    </Form>
  );
};
export default Myfrom;